package org.laobai.permission.service.impl;

import org.laobai.permission.entity.Employee;
import org.laobai.permission.mapper.EmployeeMapper;
import org.laobai.permission.service.EmployeeService;
import org.laobai.permission.struct.PageResult;
import org.laobai.permission.vo.SearchVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Objects;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiusan
 * @since 2021-11-17
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Override
    public PageResult<Employee> page(Integer currPage, Integer pageSize, SearchVO vo) {
        // 分页
        Page<Employee> employeePage = new Page<>(currPage, pageSize);

        // 条件查询
        QueryWrapper<Employee> wrapper = new QueryWrapper<>();

        if (Objects.nonNull(vo)) {
            String keyWord = vo.getKeyWord();
            if (!StringUtils.isEmpty(keyWord)) {
                wrapper.like("name", keyWord);
            }
        }
        employeePage = page(employeePage, wrapper);
        return PageResult.of(employeePage.getRecords(), employeePage.getTotal());
    }

    @Override
    public boolean saveEmployee(Employee employee) {
        return save(employee);
    }

    @Override
    public boolean updateEmployee(Employee employee) {
        return updateById(employee);
    }

    @Override
    public boolean delById(Long id) {
        return removeById(id);
    }

    @Override
    public boolean delByIds(List<Long> ids) {
        return removeByIds(ids);
    }
}
